﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COFE.Core.Lister;
using COFE.Core;
using COFE.IO.SZ.Utils;
using NUnit.Framework;

namespace COFE.IO.SZ
{
    public class SevenZipRootPropertyProvider : PropertyProviderBase<SZEntryInfo>
    {
        #region Constructor
        public SevenZipRootPropertyProvider(SevenZipDirectoryLister volume, SZEntryInfo entry)
            : base(entry)
        {
            Assert.AreEqual("", entry.CurrentItem.FileName);
            _volumeKey = entry.ListerKey;
            registerProperties(entry);

        }
        #endregion

        #region Methods

        private void registerProperties(SZEntryInfo entry)
        {
            foreach (var prop in entry.RootWrapper.ArchiveFile.GetSupportedProperty())
                switch (prop.GetType().ToString() + "." + prop.ToString())
                {
                    case "COFE.Core.InternalProperties.EmbeddedEntry":
                        break;
                    case "COFE.Core.FileSystemInfoProperties.COFEAttributes":
                        this.RegisterMethod(prop, (e, p) =>
                        {
                            return ((COFEAttributes)e.RootWrapper.ArchiveFile.GetProperty(p).Value) | COFEAttributes.NotCachable | COFEAttributes.Browsable;
                        }
                         );
                        break;
                    default:
                        this.RegisterMethod(prop, (e, p) => { return e.RootWrapper.ArchiveFile.GetProperty(p).Value; });
                        break;
                }

            RegisterMethod(FileSystemInfoProperties.FullParseName, (e, p) => { return e.RootWrapper.ArchiveFile.ParseName; });
            RegisterMethod(FileSystemInfoProperties.SecondaryVolumeKey, (e, p) => { return _volumeKey; });
            
            RegisterMethod(DirectoryInfoProperties.DirectoryType, (e, p) => { return DirectoryTypeEnum.dtRoot; });            
            RegisterMethod(DirectoryInfoProperties.IsFileBasedFS, (e, p) => { return true; });
            RegisterMethod(DirectoryInfoProperties.FileBasedFSFile, (e, p) => { return e.RootWrapper.ArchiveFile; });
            RegisterMethod(FileSystemInfoProperties.FileAttributes, (e, p) =>
            {
                return e.RootWrapper.ArchiveFile.Attributes | FileAttributes.Directory;
            });

            RegisterMethod(FileSystemInfoProperties.COFEAttributes, (e, p) => { 
                return e.RootWrapper.ArchiveFile.COFEAttributes | COFEAttributes.FileBasedFS; 
            });
        }

        #endregion

        #region Data
        private string _volumeKey;


        #endregion

        #region Public Properties

        #endregion

    }
}
